﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace Rage.UI
{
    public partial class DG_Puzzle : ChildWindow
    {
        public DG_Puzzle()
        {
            InitializeComponent();

            LB_Results1L.Text = "0 Turns";
            LB_Results2L.Text = "0 Turns";
            LB_Results3L.Text = "0 Turns";
            LB_Results4L.Text = "0 Turns";
            LB_Results1R.Text = "0 Turns";
            LB_Results2R.Text = "0 Turns";
            LB_Results3R.Text = "0 Turns";
            LB_Results4R.Text = "0 Turns";
            LB_Results1LS.Text = "0 Turns";
            LB_Results2LS.Text = "0 Turns";
            LB_Results3LS.Text = "0 Turns";
            LB_Results4LS.Text = "0 Turns";
            LB_Results1RS.Text = "0 Turns";
            LB_Results2RS.Text = "0 Turns";
            LB_Results3RS.Text = "0 Turns";
            LB_Results4RS.Text = "0 Turns";

            CB_Lock1.ItemsSource = colorsLeftImgs1.ToArray(); CB_Lock1.SelectedIndex = 0;
            CB_Lock2.ItemsSource = colorsLeftImgs2.ToArray(); CB_Lock2.SelectedIndex = 0;
            CB_Lock3.ItemsSource = colorsLeftImgs3.ToArray(); CB_Lock3.SelectedIndex = 0;
            CB_Lock4.ItemsSource = colorsLeftImgs4.ToArray(); CB_Lock4.SelectedIndex = 0;

            CB_Lock1S.ItemsSource = colorsLeftImgs5.ToArray(); CB_Lock1S.SelectedIndex = 0;
            CB_Lock2S.ItemsSource = colorsLeftImgs6.ToArray(); CB_Lock2S.SelectedIndex = 0;
            CB_Lock3S.ItemsSource = colorsLeftImgs7.ToArray(); CB_Lock3S.SelectedIndex = 0;
            CB_Lock4S.ItemsSource = colorsLeftImgs8.ToArray(); CB_Lock4S.SelectedIndex = 0;

            CB_Start1.ItemsSource = colorsLeftImgs9.ToArray(); CB_Start1.SelectedIndex = 0;
            CB_Start2.ItemsSource = colorsLeftImgs10.ToArray(); CB_Start2.SelectedIndex = 0;
            CB_Start3.ItemsSource = colorsLeftImgs11.ToArray(); CB_Start3.SelectedIndex = 0;
            CB_Start4.ItemsSource = colorsLeftImgs12.ToArray(); CB_Start4.SelectedIndex = 0;

            CB_Start1S.ItemsSource = colorsLeftImgs13.ToArray(); CB_Start1S.SelectedIndex = 0;
            CB_Start2S.ItemsSource = colorsLeftImgs14.ToArray(); CB_Start2S.SelectedIndex = 0;
            CB_Start3S.ItemsSource = colorsLeftImgs15.ToArray(); CB_Start3S.SelectedIndex = 0;
            CB_Start4S.ItemsSource = colorsLeftImgs16.ToArray(); CB_Start4S.SelectedIndex = 0;
        }


        //<Image Source="/Images/PuzzleBoss_Green.png" />
        //<Image Source="\Rage.UI.WPF;component/Images/PuzzleBoss_Blue.png" />
        private const string iconPrefix = @"/Rage.UI.WPF;component";
        private const string suffix = @".png";
        private static List<Image> colorsLeftImgs1 = new List<Image>() {
            //new Image() { Source = new BitmapImage(new Uri("/Rage.UI.WPF;component/Images/PuzzleBoss_Purple.png", UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            //new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            //new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            //new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            //new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            //new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs2 = colorsLeftImgs1;
        private static List<Image> colorsLeftImgs3 = colorsLeftImgs1;
        private static List<Image> colorsLeftImgs4 = colorsLeftImgs1;
        private static List<Image> colorsLeftImgs5 = colorsLeftImgs1;
        private static List<Image> colorsLeftImgs6 = colorsLeftImgs1;
        private static List<Image> colorsLeftImgs7 = colorsLeftImgs1;
        private static List<Image> colorsLeftImgs8 = colorsLeftImgs1;
        private static List<Image> colorsLeftImgs9 = colorsLeftImgs1;
        private static List<Image> colorsLeftImgs10= colorsLeftImgs1;
        private static List<Image> colorsLeftImgs11= colorsLeftImgs1;
        private static List<Image> colorsLeftImgs12= colorsLeftImgs1;
        private static List<Image> colorsLeftImgs13= colorsLeftImgs1;
        private static List<Image> colorsLeftImgs14= colorsLeftImgs1;
        private static List<Image> colorsLeftImgs15= colorsLeftImgs1;
        private static List<Image> colorsLeftImgs16= colorsLeftImgs1;
        /*private static List<Image> colorsLeftImgs2 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs3 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs4 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs5 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs6 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs7 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs8 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs9 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs10 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs11 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs12 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs13 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs14 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs15 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };
        private static List<Image> colorsLeftImgs16 = new List<Image>() {
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Purple" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Red" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Green" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Blue" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_Yellow" + suffix, UriKind.Relative)) },
            new Image() { Source = Icons.NewBitmapImage(new Uri(iconPrefix + "/Images/PuzzleBoss_White" + suffix, UriKind.Relative)) },
        };*/

        private static List<string> colorsLeft  = new List<string>() { "Purple", "Red", "Green", "Blue", "Yellow", "White", };
        private static List<string> colorsRight = new List<string>() { "Purple", "White", "Yellow", "Blue", "Green", "Red", };

        private string GetStringFromImage(Image src)
        {
            string s = (src.Source as BitmapImage).UriSource.ToString();
            if (s.Contains("Purple")) { return "Purple"; }
            if (s.Contains("Red")) { return "Red"; }
            if (s.Contains("Green")) { return "Green"; }
            if (s.Contains("Blue")) { return "Blue"; }
            if (s.Contains("Yellow")) { return "Yellow"; }
            if (s.Contains("White")) { return "White"; }
            return "Purple";
        }

        private void CB_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (CB_Lock1.SelectedIndex < 0 || CB_Start1.SelectedIndex < 0
                || CB_Lock2.SelectedIndex < 0 || CB_Start2.SelectedIndex < 0
                || CB_Lock3.SelectedIndex < 0 || CB_Start3.SelectedIndex < 0
                || CB_Lock4.SelectedIndex < 0 || CB_Start4.SelectedIndex < 0
                || CB_Lock1S.SelectedIndex < 0 || CB_Start1S.SelectedIndex < 0
                || CB_Lock2S.SelectedIndex < 0 || CB_Start2S.SelectedIndex < 0
                || CB_Lock3S.SelectedIndex < 0 || CB_Start3S.SelectedIndex < 0
                || CB_Lock4S.SelectedIndex < 0 || CB_Start4S.SelectedIndex < 0)
            { return; }

            int numTurns1L = GetNumTurnsLeft(GetStringFromImage(CB_Lock1.SelectedItem as Image), GetStringFromImage(CB_Start1.SelectedItem as Image));
            int numTurns2L = GetNumTurnsLeft(GetStringFromImage(CB_Lock2.SelectedItem as Image), GetStringFromImage(CB_Start2.SelectedItem as Image));
            int numTurns3L = GetNumTurnsLeft(GetStringFromImage(CB_Lock3.SelectedItem as Image), GetStringFromImage(CB_Start3.SelectedItem as Image));
            int numTurns4L = GetNumTurnsLeft(GetStringFromImage(CB_Lock4.SelectedItem as Image), GetStringFromImage(CB_Start4.SelectedItem as Image));
            int numTurns1R = GetNumTurnsRight(GetStringFromImage(CB_Lock1.SelectedItem as Image), GetStringFromImage(CB_Start1.SelectedItem as Image));
            int numTurns2R = GetNumTurnsRight(GetStringFromImage(CB_Lock2.SelectedItem as Image), GetStringFromImage(CB_Start2.SelectedItem as Image));
            int numTurns3R = GetNumTurnsRight(GetStringFromImage(CB_Lock3.SelectedItem as Image), GetStringFromImage(CB_Start3.SelectedItem as Image));
            int numTurns4R = GetNumTurnsRight(GetStringFromImage(CB_Lock4.SelectedItem as Image), GetStringFromImage(CB_Start4.SelectedItem as Image));
            int numTurns1LS = GetNumTurnsLeft(GetStringFromImage(CB_Lock1S.SelectedItem as Image), GetStringFromImage(CB_Start1S.SelectedItem as Image));
            int numTurns2LS = GetNumTurnsLeft(GetStringFromImage(CB_Lock2S.SelectedItem as Image), GetStringFromImage(CB_Start2S.SelectedItem as Image));
            int numTurns3LS = GetNumTurnsLeft(GetStringFromImage(CB_Lock3S.SelectedItem as Image), GetStringFromImage(CB_Start3S.SelectedItem as Image));
            int numTurns4LS = GetNumTurnsLeft(GetStringFromImage(CB_Lock4S.SelectedItem as Image), GetStringFromImage(CB_Start4S.SelectedItem as Image));
            int numTurns1RS = GetNumTurnsRight(GetStringFromImage(CB_Lock1S.SelectedItem as Image), GetStringFromImage(CB_Start1S.SelectedItem as Image));
            int numTurns2RS = GetNumTurnsRight(GetStringFromImage(CB_Lock2S.SelectedItem as Image), GetStringFromImage(CB_Start2S.SelectedItem as Image));
            int numTurns3RS = GetNumTurnsRight(GetStringFromImage(CB_Lock3S.SelectedItem as Image), GetStringFromImage(CB_Start3S.SelectedItem as Image));
            int numTurns4RS = GetNumTurnsRight(GetStringFromImage(CB_Lock4S.SelectedItem as Image), GetStringFromImage(CB_Start4S.SelectedItem as Image));

            LB_Results1L.Text = string.Format("{0} Turns", numTurns1L);
            LB_Results2L.Text = string.Format("{0} Turns", numTurns2L);
            LB_Results3L.Text = string.Format("{0} Turns", numTurns3L);
            LB_Results4L.Text = string.Format("{0} Turns", numTurns4L);
            LB_Results1R.Text = string.Format("{0} Turns", numTurns1R);
            LB_Results2R.Text = string.Format("{0} Turns", numTurns2R);
            LB_Results3R.Text = string.Format("{0} Turns", numTurns3R);
            LB_Results4R.Text = string.Format("{0} Turns", numTurns4R);
            LB_Results1LS.Text = string.Format("{0} Turns", numTurns1LS);
            LB_Results2LS.Text = string.Format("{0} Turns", numTurns2LS);
            LB_Results3LS.Text = string.Format("{0} Turns", numTurns3LS);
            LB_Results4LS.Text = string.Format("{0} Turns", numTurns4LS);
            LB_Results1RS.Text = string.Format("{0} Turns", numTurns1RS);
            LB_Results2RS.Text = string.Format("{0} Turns", numTurns2RS);
            LB_Results3RS.Text = string.Format("{0} Turns", numTurns3RS);
            LB_Results4RS.Text = string.Format("{0} Turns", numTurns4RS);

            if (numTurns1L == numTurns1R) { LB_Results1.Text = string.Format("<-{0}->", numTurns1L); } else if (numTurns1L < numTurns1R) { LB_Results1.Text = string.Format("<-{0}   ", numTurns1L); } else { LB_Results1.Text = string.Format("   {0}->", numTurns1R); }
            if (numTurns2L == numTurns2R) { LB_Results2.Text = string.Format("<-{0}->", numTurns2L); } else if (numTurns2L < numTurns2R) { LB_Results2.Text = string.Format("<-{0}   ", numTurns2L); } else { LB_Results2.Text = string.Format("   {0}->", numTurns2R); }
            if (numTurns3L == numTurns3R) { LB_Results3.Text = string.Format("<-{0}->", numTurns3L); } else if (numTurns3L < numTurns3R) { LB_Results3.Text = string.Format("<-{0}   ", numTurns3L); } else { LB_Results3.Text = string.Format("   {0}->", numTurns3R); }
            if (numTurns4L == numTurns4R) { LB_Results4.Text = string.Format("<-{0}->", numTurns4L); } else if (numTurns4L < numTurns4R) { LB_Results4.Text = string.Format("<-{0}   ", numTurns4L); } else { LB_Results4.Text = string.Format("   {0}->", numTurns4R); }
            if (numTurns1LS == numTurns1RS) { LB_Results1S.Text = string.Format("<-{0}->", numTurns1LS); } else if (numTurns1LS < numTurns1RS) { LB_Results1S.Text = string.Format("<-{0}   ", numTurns1LS); } else { LB_Results1S.Text = string.Format("   {0}->", numTurns1RS); }
            if (numTurns2LS == numTurns2RS) { LB_Results2S.Text = string.Format("<-{0}->", numTurns2LS); } else if (numTurns2LS < numTurns2RS) { LB_Results2S.Text = string.Format("<-{0}   ", numTurns2LS); } else { LB_Results2S.Text = string.Format("   {0}->", numTurns2RS); }
            if (numTurns3LS == numTurns3RS) { LB_Results3S.Text = string.Format("<-{0}->", numTurns3LS); } else if (numTurns3LS < numTurns3RS) { LB_Results3S.Text = string.Format("<-{0}   ", numTurns3LS); } else { LB_Results3S.Text = string.Format("   {0}->", numTurns3RS); }
            if (numTurns4LS == numTurns4RS) { LB_Results4S.Text = string.Format("<-{0}->", numTurns4LS); } else if (numTurns4LS < numTurns4RS) { LB_Results4S.Text = string.Format("<-{0}   ", numTurns4LS); } else { LB_Results4S.Text = string.Format("   {0}->", numTurns4RS); }
        }

        private int GetNumTurnsRight(string colorL, string colorS)
        {
            bool sol = false;
            int cur = colorsLeft.IndexOf(colorL);
            int numTurns = 0;
            while (!sol) {
                if (colorS == colorsLeft[cur]) {
                    sol = true;
                } else {
                    cur++;
                    numTurns++;
                }
                if (cur > 5) { cur = 0; }
            }
            return numTurns;
        }
        private int GetNumTurnsLeft(string colorL, string colorS)
        {
            bool sol = false;
            int cur = colorsRight.IndexOf(colorL);
            int numTurns = 0;
            while (!sol) {
                if (colorS == colorsRight[cur]) {
                    sol = true;
                } else {
                    cur++;
                    numTurns++;
                }
                if (cur > 5) { cur = 0; }
            }
            return numTurns;
        }

        private void BT_CopyToClipboard_Click(object sender, RoutedEventArgs e)
        {
            Clipboard.SetText(
                string.Format("NORTH: Lock 1: {0} || Lock 2: {1} || Lock 3: {2} || Lock 4: {3} "
                      + "..... SOUTH: Lock 1: {4} || Lock 2: {5} || Lock 3: {6} || Lock 4: {7}",
                    LB_Results1.Text, LB_Results2.Text, LB_Results3.Text, LB_Results4.Text,
                    LB_Results1S.Text, LB_Results2S.Text, LB_Results3S.Text, LB_Results4S.Text)
                );
        }

        private void OKButton_Click(object sender, RoutedEventArgs e) { this.DialogResult = true; }
    }
}

